﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelLoader;
using MDSAdministration;

namespace MDSAdministrationTest
{
    public class Common
    {
        public static ServerMDSDetails ServerA;
        public static ServerMDSDetails ServerB;

        public DataSet dsA;
        public DataSet dsB;

        public static void LoadServer()
        {
            if (ServerA == null)
            {
                Common.ServerA = new ServerMDSDetails();
                ServerA.ServerName = ".";
                ServerA.Database = "MDSTest";
                ServerA.ModelVersion = "VERSION_1";
                ServerA.Model = "SandBox";

                ServerA.schemaVersion = new CompareSystem();
                ServerA.schemaVersion.Version = "11.1.0.0";
            }

            if (ServerB == null)
            {
                Common.ServerB = new ServerMDSDetails();
                ServerB.ServerName = ".";
                ServerB.Database = "MDSTestB";
                ServerB.ModelVersion = "VERSION_1";
                ServerB.Model = "SandBox";

                ServerB.schemaVersion = new CompareSystem();
                ServerB.schemaVersion.Version = "11.1.0.0";
            }
        }

        public void LoadSampleData(string filename)
        {
            if (dsA == null || dsB == null)
            {
                ExcelHelper eh = new ExcelHelper();
                eh.FileName = filename;
                eh.SetConnectionString();
                List<SheetDetails> lSheets = eh.GetExcelSheetNames();
                Dictionary<string, DataTable> ds = new Dictionary<string, DataTable>();

                foreach (var sheet in lSheets)
                {
                    DataTable dt = eh.ReadExcelSheet(sheet.SheetName, true);
                    ds.Add(sheet.Name, dt);
                }

                dsA = new DataSet();
                dsA.Tables.Add(ds["Model_A"]);
                dsA.Tables.Add(ds["View_A"]);
                dsA.Tables.Add(ds["AttributeGroup_A"]);
                dsA.Tables.Add(ds["AttributeGroupDetail_A"]);
                dsB = new DataSet();
                dsB.Tables.Add(ds["Model_B"]);
                dsB.Tables.Add(ds["View_B"]);
                dsB.Tables.Add(ds["AttributeGroup_B"]);
                dsB.Tables.Add(ds["AttributeGroupDetail_B"]);
            }
        }
    }
}
